package com.example.wzdjcrdpassword.repository;

import com.example.wzdjcrdpassword.entity.Config;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface ConfigRepository extends JpaRepository<Config, Long> {
    
    @Query("SELECT c FROM Config c WHERE c.configType = :configType AND c.configKey = :configKey AND c.configValue = :configValue AND c.isAvailable = 'YES' AND c.isDeleted = 'NO'")
    Optional<Config> findByTypeKeyValueAndAvailable(@Param("configType") String configType, 
                                                   @Param("configKey") String configKey, 
                                                   @Param("configValue") String configValue);
    
    Optional<Config> findByBusinessIdAndIsDeleted(String businessId, String isDeleted);
    
    Optional<Config> findByConfigTypeAndConfigKeyAndIsDeleted(String configType, String configKey, String isDeleted);
    
    @Query("SELECT c FROM Config c WHERE c.isAvailable = 'YES' AND c.isDeleted = 'NO'")
    List<Config> findAllAvailableConfigs();
}